package org.example.high.writer;

import com.alibaba.fastjson.JSON;
import dev.langchain4j.agent.tool.ToolSpecifications;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.Result;
import org.example.ToolDemo;

import java.util.List;

/**
 * @author fish_temp_author
 * @since fish_temp_since
 */
public class AiWriterDemo {
    public static void main(String[] args) throws NoSuchMethodException {
        AiWriter demo = AiServices.<AiWriter>builder(AiWriter.class)
                // 大语言
                .chatLanguageModel(OpenAiChatModel.builder()
                        .apiKey("demo")
                        .modelName("gpt-4o-mini")
                        .build())
                // 记忆
                .chatMemory(MessageWindowChatMemory.withMaxMessages(10))
                // 工具
                .tools(List.of(
                        ToolSpecifications.toolSpecificationFrom(ToolDemo.Tool.class.getMethod("getCurrentDate")),
                        ToolSpecifications.toolSpecificationFrom(ToolDemo.Tool.class.getMethod("getUserName")),
                        ToolSpecifications.toolSpecificationFrom(ToolDemo.Tool.class.getMethod("getBmi", String.class, String.class))
                ))
                .build();
        System.out.println(demo.write("介绍一下参数校验", "python", 100));
        System.out.println(demo.write("介绍一下参数校验", "springboot", 100));
        System.out.println(demo.write("介绍一下参数校验", "js", 100));
        System.out.println(demo.write("介绍一下参数校验", ".net", 100));
        System.out.println(demo.write("今天的日期", ".net", 100));

        Result<String> result = demo.coder("二分查找", "c#");
        System.out.println(result.content());
        System.out.println(result.finishReason());
        System.out.println(result.sources());
        System.out.println(result.tokenUsage());
        System.out.println(result.toolExecutions());

    }
}
